#include "../../source/server.hpp"

void OnConnected(const Connection::Ptr &conn)
{
    DBG_LOG("new connection: %p", conn.get());
}
void OnClosed(const Connection::Ptr &conn)
{
    DBG_LOG("close connection: %p", conn.get());
}
void OnMessage(const Connection::Ptr &conn, Buffer *buff)
{
    DBG_LOG("%s", buff->ReadPosition());
    buff->MoveReadOffset(buff->ReadAbleSize());
    std::string str =  "hello world";
    conn->Send(str.c_str(), str.size());
}
int main()
{
    TcpServer server(8080);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);
    server.SetConnectedCallBack(OnConnected);
    server.SetClosedCallBack(OnClosed);
    server.SetMessageCallBack(OnMessage);
    server.Start();
}